package com.neo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.neo.controller.feign.ProviderFeignClient;

/**
 * @Author liulonglong
 * @Description 消费端controller
 * @Date 17:13 2019/9/25
 * @Param
 * @return
 **/
@RestController
@EnableFeignClients
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private ProviderFeignClient feignClient;

    /**
     * @return java.lang.String
     * @Author liulonglong
     * @Description restTemplate调用nacos服务 nacos-provider
     * @Date 17:40 2019/9/25
     * @Param []
     **/
    @GetMapping("/hello-provider-rest")
    public String index() {
        String result = restTemplate.getForObject("http://nacos-provider/hello?name=万佳莹", String.class);
        return "Return : " + result;

    }

    /**
     * @return java.lang.String
     * @Author liulonglong
     * @Description feign调用nacos服务 nacos-provider
     * @Date 17:42 2019/9/25
     * @Param [name]
     **/
    @GetMapping("/hello-provider-feign")
    public String hello(@RequestParam(name = "name", required = false) String name) {
        String s = feignClient.index(name);
        return s;
    }

}